using System;
using System.Collections.Generic;
using System.Xml;
using System.Collections.ObjectModel;

namespace planning
{
	public class Labo : Salle
	{
		// ----- ATTRIBUTS -----


		// ----- CONSTRUCTEURS -----
		public Labo()
		{
			// Start of user code for default constructor
			// End of user code for default constructor
		}

		// ----- ACCESSEURS -----



		private static Dictionary<string, Labo> references = new Dictionary<string, Labo>();

		public static new Labo fromXml(XmlNode node)
		{
			Labo labo;
			XmlNode refAttribute = node.SelectSingleNode("@ref");
			XmlNode idAttribute = node.SelectSingleNode("@id");

			if(refAttribute != null) {
				if(references.ContainsKey(refAttribute.Value)) {
					return references[refAttribute.Value];
				} else {
					labo = new Labo();
					references.Add(refAttribute.Value, labo);
					return labo;
				}
			}

			if(idAttribute != null && references.ContainsKey(idAttribute.Value)) {
				labo = references[idAttribute.Value];
			} else {
				labo = new Labo();

				if(idAttribute != null) {
					references.Add(idAttribute.Value, labo);
				}
			}

			if(node.SelectSingleNode("@nom") != null)
				labo.Nom = node.SelectSingleNode("@nom").Value;

			

			return labo;

		}

        public override string Ref
        {
            get
            {
                return "lab-" + Nom.ToLower();
            }
        }

        public override XmlElement toXml(XmlDocument document)
		{
            // Start of user code for toXml
            XmlElement element = document.CreateElement("Labo");
            XmlAttribute refAttribute = document.CreateAttribute("id");
            refAttribute.Value = Ref;
            element.Attributes.Append(refAttribute);

            XmlAttribute titreAttribute = document.CreateAttribute("nom");
            titreAttribute.Value = Nom;
            element.Attributes.Append(titreAttribute);

            return element;
			// End of user code for toXml
		}


	}

}
